Telegram Group & Telegram Channel
🐍 Лайфхак: Ленивая загрузка огромных JSON-файлов с помощью ijson
Ситуация:
У вас огромный JSON-файл (гигабайты данных), который не помещается в память.
Стандартный json.load() просто упадёт с OOM.

Решение:
Используйте библиотеку ijson — это парсер JSON "на лету", который читает данные потоково, как SAX для XML.

Пример:


import ijson

with open('huge.json', 'rb') as f:
# Предположим, внутри файла — массив объектов
for obj in ijson.items(f, 'item'):
# obj — очередной элемент массива, не вся структура целиком!
# Можно обрабатывать на лету и не держать в памяти гигабайты
process(obj) # Ваш код обработки

Плюсы:

Поддерживает вложенные структуры, сложные схемы JSON

Минимальное потребление памяти

Подходит для любых задач потоковой обработки

🔥 Если часто работаете с большими файлами — этот инструмент реально спасает время и ресурсы!



tg-me.com/pro_python_code/1838
Create:
Last Update:

🐍 Лайфхак: Ленивая загрузка огромных JSON-файлов с помощью ijson
Ситуация:
У вас огромный JSON-файл (гигабайты данных), который не помещается в память.
Стандартный json.load() просто упадёт с OOM.

Решение:
Используйте библиотеку ijson — это парсер JSON "на лету", который читает данные потоково, как SAX для XML.

Пример:


import ijson

with open('huge.json', 'rb') as f:
# Предположим, внутри файла — массив объектов
for obj in ijson.items(f, 'item'):
# obj — очередной элемент массива, не вся структура целиком!
# Можно обрабатывать на лету и не держать в памяти гигабайты
process(obj) # Ваш код обработки

Плюсы:

Поддерживает вложенные структуры, сложные схемы JSON

Минимальное потребление памяти

Подходит для любых задач потоковой обработки

🔥 Если часто работаете с большими файлами — этот инструмент реально спасает время и ресурсы!

BY Python RU


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/pro_python_code/1838

View MORE
Open in Telegram


Python RU Telegram | DID YOU KNOW?

Date: |

The lead from Wall Street offers little clarity as the major averages opened lower on Friday and then bounced back and forth across the unchanged line, finally finishing mixed and little changed.The Dow added 33.18 points or 0.10 percent to finish at 34,798.00, while the NASDAQ eased 4.54 points or 0.03 percent to close at 15,047.70 and the S&P 500 rose 6.50 points or 0.15 percent to end at 4,455.48. For the week, the Dow rose 0.6 percent, the NASDAQ added 0.1 percent and the S&P gained 0.5 percent.The lackluster performance on Wall Street came on uncertainty about the outlook for the markets following recent volatility.

Telegram Gives Up On Crypto Blockchain Project

Durov said on his Telegram channel today that the two and a half year blockchain and crypto project has been put to sleep. Ironically, after leaving Russia because the government wanted his encryption keys to his social media firm, Durov’s cryptocurrency idea lost steam because of a U.S. court. “The technology we created allowed for an open, free, decentralized exchange of value and ideas. TON had the potential to revolutionize how people store and transfer funds and information,” he wrote on his channel. “Unfortunately, a U.S. court stopped TON from happening.”

Python RU from ye


Telegram Python RU
FROM USA